{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1233
  Verdict: Accepted
}
uses SysUtils, Math;
var
   i,n,r1,r2,cr:longint;
 
function count(n:longint):longint;
var
   k:longint;
   d:array[0..9] of boolean;
begin
fillchar(d,sizeof(d),false);
k:=n;
while k>0 do begin
      d[k mod 10]:=true;
      k:=k div 10;
end;
result:=0;
for k:=0 to 9 do
    if d[k] then inc(result);
end;
 
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(n);
cr:=count(n);
r1:=n;
r2:=n+1;
while count(r1)>2 do dec(r1);
while count(r2)>2 do inc(r2);
if abs(n-r1)>abs(n-r2) then write(r2) else write(r1);
end.